package com.tianyi.sfzy1.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tianyi.sfzy1.domain.Privatemessage;
import com.tianyi.sfzy1.mapper.PrivatemessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PrivatemessageService {
    @Autowired
    private PrivatemessageMapper privatemessageMapper;
    //插入用户提问的问题和相关信息
    public int insertQuestion(Privatemessage privatemessage){
        return privatemessageMapper.insertQuestion(privatemessage);
    }

    //根据会员编号和咨询师编号查询私信列表
    public List<Privatemessage> selectMessage(int consultantId){
        return privatemessageMapper.selectMessage(consultantId);
    }

    //根据咨询师编号查询私信列表
    public List<Privatemessage> selectById(int consultantId){
        return privatemessageMapper.selectById(consultantId);
    }

    //根据咨询师编号查询私信列表(分页)
    public PageInfo<Privatemessage> selectByIdPage2(int consultantId, int pageNum, int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Privatemessage> privatemessages = privatemessageMapper.selectById2(consultantId,pageNum,pageSize);
        PageInfo<Privatemessage> pageInfo = new PageInfo<>(privatemessages);
        return pageInfo;
    }

    //根据id修改回复内容
    public int updateAnswer(int messageId,String replyContent){
        return privatemessageMapper.updateAnswer(messageId,replyContent);
    }

    //根据id删除私信
    public int deleteMessage(int messageId){
        return privatemessageMapper.deleteMessage(messageId);
    }

    //根据用户姓名和咨询师id查询私信列表(模糊查询)
    public List<Privatemessage> selectByUsername666(String realname,int consultantId){
        return privatemessageMapper.selectByUsername666(realname,consultantId);
    }

    //根据私信id删除私信信息(批量删除)
    public int deleteMessageByIds(List<Integer> messageId){
        return privatemessageMapper.deleteMessageByIds(messageId);
    }

    //根据咨询师id查询私信的数量
    public int selectCount2(int consultantId){
        return privatemessageMapper.selectCount2(consultantId);
    }
}
